package cn.cs.yangtai.controller;

import cn.cs.yangtai.entity.Blog;
import cn.cs.yangtai.entity.Classification;
import cn.cs.yangtai.entity.vo.PageResult;
import cn.cs.yangtai.entity.vo.ResponsePojo;
import cn.cs.yangtai.service.ClassificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Classification)表控制层
 *
 * @author makejava
 * @since 2024-12-12 09:03:47
 */
@RestController
@Tag(name = "分类")
@CrossOrigin
@RequestMapping("classification")
public class ClassificationController {
    /**
     * 服务对象
     */
    @Resource
    private ClassificationService classificationService;

    /**
     * 分页查询
     *
     * @param cuttentPage 本页
     * @param pageSize    分页大小
     * @return 查询结果
     */
    @GetMapping
    public ResponsePojo<PageResult<Classification>> queryByPage(Integer cuttentPage, Integer pageSize) {
        PageResult<Classification> result=classificationService.queryByPage(cuttentPage,pageSize);
        return ResponsePojo.success(result);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Classification> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.classificationService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param classification 实体
     * @return 新增结果
     */
    @Operation(summary = "添加分类")
    @PostMapping
    public ResponseEntity<String> add(@RequestBody  Classification classification) {
        classificationService.insert(classification);
        return ResponseEntity.ok().body("分类添加成功");
    }

    /**
     * 编辑数据
     *
     * @param classification 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Classification> edit(Classification classification) {
        return ResponseEntity.ok(this.classificationService.update(classification));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.classificationService.deleteById(id));
    }

}

